package render

import (
    "net/http"
    "encoding/json"
)

var (
    jsonContentType = "application/json; charset=utf-8"
)

type JsonRender interface {
    Instance(data interface{}) Render
}

type Json struct {
    Data interface{}
}

func (this *Json) Instance(data interface{}) Render {
    return &Json{Data: data}
}

func (this *Json) Render(w http.ResponseWriter, headerCode int) error {
    setContentType(w, jsonContentType)
    w.WriteHeader(headerCode)
    return json.NewEncoder(w).Encode(this.Data)
}
